package com.study.meituan.activity;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import com.study.meituan.R;
import com.study.meituan.adapter.CaiDanItemAdapter;
import com.study.meituan.adapter.CaiDanLeiBieAdapter;
import com.study.meituan.entity.CaiDanItemEntity;
import com.study.meituan.entity.CaiDanLeiBieEntity;
import com.study.meituan.widget.MyListView;

import android.app.Activity;
import android.os.Bundle;
import android.text.InputFilter.LengthFilter;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class activity_ShangDianCaiDan extends activity_HuaDongGuanBi {
	// private static final String[] mMenus = { "猪肉", "鸡肉", "狗肉", "烟",
	// "酒", "海洛因", "大麻", "冰毒", "茄子" };
	private List<CaiDanLeiBieEntity> mlist;
	
	private MyListView mListView1;
	private MyListView mListView2;
	String TAG = "Shang_dian_xiangqing_activity";

	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.shang_dian_cai_dan);
		initView();

	}

	private void initView() {
		mlist = new ArrayList<CaiDanLeiBieEntity>();
		
		TextView textView = (TextView) this.findViewById(R.id.text1);
		mListView1 = (MyListView) findViewById(R.id.list1);
		mListView2 = (MyListView) findViewById(R.id.list2);
		Animation ani = new TranslateAnimation(310f, -400f, 0.0f, 0.0f);
		ani.setDuration(10000);
		ani.setRepeatCount(500);
		ani.setRepeatMode(1);
		textView.startAnimation(ani);

		CaiDanLeiBieEntity leibie1 = new CaiDanLeiBieEntity();
		leibie1.setIcon(R.drawable.ic_zoom_in);
		leibie1.setLei_bie("烟");
		CaiDanLeiBieEntity leibie2 = new CaiDanLeiBieEntity();
		leibie2.setIcon(R.drawable.ic_zoom_out);
		leibie2.setLei_bie("酒");
		CaiDanLeiBieEntity leibie3 = new CaiDanLeiBieEntity();
		leibie3.setIcon(R.drawable.ic_zoom_in);
		leibie3.setLei_bie("饭");
		CaiDanLeiBieEntity leibie4 = new CaiDanLeiBieEntity();
		leibie4.setIcon(R.drawable.ic_zoom_out);
		leibie4.setLei_bie("菜");
		CaiDanLeiBieEntity leibie5 = new CaiDanLeiBieEntity();

		leibie5.setLei_bie("饮料");

		mlist.add(leibie1);
		mlist.add(leibie2);
		mlist.add(leibie3);
		mlist.add(leibie4);
		mlist.add(leibie5);

		CaiDanLeiBieAdapter adater1 = new CaiDanLeiBieAdapter(
				activity_ShangDianCaiDan.this, mlist);
		//mListView1.setSelection(0);
		mListView1.setAdapter(adater1);
		//mListView1.Items[0].Selected = true;
		mListView1.setOnItemClickListener(new ItemClick());
		//mListView1.setItemChecked(1, true);
		//mListView1.getItemIdAtPosition(1).setSelected = True
//		mListView1.post(new Runnable() {
//            @Override
//            public void run() {
//               // lastCheckedOption = actionList.getChildAt(1).findViewById(R.id.recharge_method_checked);
//               // lastCheckedOption.setVisibility(View.VISIBLE);
//            	mListView1.setItemChecked(1, true);
//            }
//        });

	}

	private class ItemClick implements OnItemClickListener {
		private List<CaiDanItemEntity> items;
		
		// @Override
		public void onItemClick(AdapterView<?> parent, View view, int position,
				long id) {
			mListView1.smoothScrollToPositionFromTop(position, 0);

			// String[] items = new String[(position + 1) * 2];
			// for(int i=0;i<items.length;i++) {
			// items[i] = mMenus[position] + "中的数据：" + i;
			// }
			// mListView2.setAdapter(new
			// ArrayAdapter<String>(activity_ShangDianCaiDan.this,
			// android.R.layout.simple_list_item_1, items));
			//
			
           String [] nums=new String[(position+1)*2];
           items= new ArrayList<CaiDanItemEntity>();
           
           for(int i=0;i<nums.length;i++){
        	   CaiDanItemEntity item=new CaiDanItemEntity(R.drawable.ic_launcher, mlist.get(position).getLei_bie()+i, "月售300",
      					"147", "15");
        	   
   		    items.add(item);
           }
			
           CaiDanItemAdapter adapter2=new CaiDanItemAdapter(activity_ShangDianCaiDan.this, items);
           mListView2.setAdapter(adapter2);
       
      

		}
	}
}
